﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace TuyennvLibrary.ServerApi.Sms
{
    public class MsgObject
    {
        public long moId { get; set; }
        public string userid { get; set; }
        public string command_code { get; set; }
        public string serviceid { get; set; }
        public string mobile_operator { get { return getMobileOperator(this.userid); } set { mobile_operator = value; } }
        public string message { get; set; }
        public int msg_type { get; set; }
        public string request_id { get; set; }
        public DateTime request_time { get; set; }
        public string subcodes { get; set; }
        public MsgObject()
        {
			this.moId = 0;
			this.userid = string.Empty;
			this.command_code = string.Empty;
			this.serviceid = string.Empty;
			this.message = string.Empty;
			this.msg_type = 0;
			this.request_id = string.Empty;
			this.request_time = DateTime.Now;
                        
        }
        public string getContentEx(int index)
        {
            string real_command = (!string.IsNullOrEmpty(subcodes)) ? command_code + " " + subcodes : command_code;
            string content = Regex.Replace(message.Trim(), "\\s+", " ");
            content = Regex.Replace(content.ToUpper(), "^" + real_command.ToUpper(), "").Trim();
            try
            {
                return content.Split(' ')[index - 1];
            }
            catch (Exception)
            {
            }
            return string.Empty;
        }
        public string getRealCommand()
        {
            string real_command = (!string.IsNullOrEmpty(subcodes)) ? command_code + " " + subcodes : command_code;
            return real_command;
        }
        private string getMobileOperator(string mobileNumber)
        {
            if (string.IsNullOrEmpty(mobileNumber))
                return "UNKNOWN";
            if (mobileNumber.StartsWith("+"))
            {
                mobileNumber = mobileNumber.Substring(1);
            }
            if (mobileNumber.StartsWith("8498") || mobileNumber.StartsWith("+8498")
                    || mobileNumber.StartsWith("098") || mobileNumber.StartsWith("98")
                    || mobileNumber.StartsWith("8497") || mobileNumber.StartsWith("+8497")
                    || mobileNumber.StartsWith("097") || mobileNumber.StartsWith("97")
                    || mobileNumber.StartsWith("8496") || mobileNumber.StartsWith("+8496")
                    || mobileNumber.StartsWith("096") || mobileNumber.StartsWith("96")
                    || mobileNumber.StartsWith("8416") || mobileNumber.StartsWith("+8416")
                    || mobileNumber.StartsWith("016") || mobileNumber.StartsWith("16"))
            {
                return "VIETEL";
            }
            else if (mobileNumber.StartsWith("8490") || mobileNumber.StartsWith("+8490")
                  || mobileNumber.StartsWith("090") || mobileNumber.StartsWith("90")
                  || mobileNumber.StartsWith("8493") || mobileNumber.StartsWith("+8493")
                  || mobileNumber.StartsWith("093") || mobileNumber.StartsWith("93")
                  || mobileNumber.StartsWith("84120") || mobileNumber.StartsWith("+84120")
                  || mobileNumber.StartsWith("0120") || mobileNumber.StartsWith("120")
                  || mobileNumber.StartsWith("84121") || mobileNumber.StartsWith("+84121")
                  || mobileNumber.StartsWith("0121") || mobileNumber.StartsWith("121")
                  || mobileNumber.StartsWith("84122") || mobileNumber.StartsWith("+84122")
                  || mobileNumber.StartsWith("0122") || mobileNumber.StartsWith("122")
                  || mobileNumber.StartsWith("84126") || mobileNumber.StartsWith("+84126")
                  || mobileNumber.StartsWith("0126") || mobileNumber.StartsWith("126")
                  || mobileNumber.StartsWith("84128") || mobileNumber.StartsWith("+84128")
                  || mobileNumber.StartsWith("0128") || mobileNumber.StartsWith("128"))
            {
                return "VMS";
            }
            else if (((mobileNumber.StartsWith("04390") || mobileNumber.StartsWith("043912") || mobileNumber.StartsWith("043913")
                  || mobileNumber.StartsWith("043917") || mobileNumber.StartsWith("043918")
                  || mobileNumber.StartsWith("043919") || mobileNumber.StartsWith("043610")
                  || mobileNumber.StartsWith("043611") || mobileNumber.StartsWith("043612")) && mobileNumber.Length == 10)
                  || ((mobileNumber.StartsWith("844390") || mobileNumber.StartsWith("8443912") || mobileNumber.StartsWith("8443913")
                  || mobileNumber.StartsWith("8443917") || mobileNumber.StartsWith("8443918")
                  || mobileNumber.StartsWith("8443919") || mobileNumber.StartsWith("8443610")
                  || mobileNumber.StartsWith("8443611") || mobileNumber.StartsWith("8443612")) && mobileNumber.Length == 11) ||//CITY HN
                  ((mobileNumber.StartsWith("08390") || mobileNumber.StartsWith("083912") || mobileNumber.StartsWith("083913")
                  || mobileNumber.StartsWith("083917") || mobileNumber.StartsWith("083918")
                  || mobileNumber.StartsWith("083919") || mobileNumber.StartsWith("083610")
                  || mobileNumber.StartsWith("083611") || mobileNumber.StartsWith("083612")) && mobileNumber.Length == 10)
                  || ((mobileNumber.StartsWith("848390") || mobileNumber.StartsWith("8483912") || mobileNumber.StartsWith("8483913")
                  || mobileNumber.StartsWith("8483917") || mobileNumber.StartsWith("8483918")
                  || mobileNumber.StartsWith("8483919") || mobileNumber.StartsWith("8483610")
                  || mobileNumber.StartsWith("8483611") || mobileNumber.StartsWith("8483612")) && mobileNumber.Length == 11))
            {
                return "CITY";
            }
            else if (mobileNumber.StartsWith("8491") || mobileNumber.StartsWith("+8491")
                  || mobileNumber.StartsWith("091") || mobileNumber.StartsWith("91")
                  || mobileNumber.StartsWith("8494") || mobileNumber.StartsWith("+8494")
                  || mobileNumber.StartsWith("094") || mobileNumber.StartsWith("94")
                  || mobileNumber.StartsWith("84123") || mobileNumber.StartsWith("+84123")
                  || mobileNumber.StartsWith("0123") || mobileNumber.StartsWith("123")
                  || mobileNumber.StartsWith("84124") || mobileNumber.StartsWith("+84124")
                  || mobileNumber.StartsWith("0124") || mobileNumber.StartsWith("124")
                  || mobileNumber.StartsWith("84125") || mobileNumber.StartsWith("+84125")
                  || mobileNumber.StartsWith("0125") || mobileNumber.StartsWith("125")
                  || mobileNumber.StartsWith("84127") || mobileNumber.StartsWith("+84127")
                  || mobileNumber.StartsWith("0127") || mobileNumber.StartsWith("127")
                  || mobileNumber.StartsWith("84129") || mobileNumber.StartsWith("+84129")
                  || mobileNumber.StartsWith("0129") || mobileNumber.StartsWith("129")
                  )
            {
                return "GPC";
            }
            else if (mobileNumber.StartsWith("8495") || mobileNumber.StartsWith("+8495")
                  || mobileNumber.StartsWith("095") || mobileNumber.StartsWith("95"))
            {
                return "SFONE";
            }
            else if (mobileNumber.StartsWith("8492") || mobileNumber.StartsWith("+8492")
                  || mobileNumber.StartsWith("092") || mobileNumber.StartsWith("92")
                //nhanln-2012/02/10
                  || mobileNumber.StartsWith("84186") || mobileNumber.StartsWith("+84186")
                  || mobileNumber.StartsWith("0186") || mobileNumber.StartsWith("186")
                  || mobileNumber.StartsWith("84188") || mobileNumber.StartsWith("+84188")
                  || mobileNumber.StartsWith("0188") || mobileNumber.StartsWith("188"))
            {
                return "VNM";
            }
            else if (mobileNumber.StartsWith("8496") || mobileNumber.StartsWith("+8496")
                  || mobileNumber.StartsWith("096") || mobileNumber.StartsWith("96")
                  )
            {
                return "EVN";
            }
            else if (mobileNumber.StartsWith("84199") || mobileNumber.StartsWith("+84199")
                  || mobileNumber.StartsWith("0199") || mobileNumber.StartsWith("199")
                //nhanln-2012/02/10
                  || (mobileNumber.StartsWith("8499") && mobileNumber.Length == 11)
                  || (mobileNumber.StartsWith("+8499") && mobileNumber.Length == 12)
                  || (mobileNumber.StartsWith("099") && mobileNumber.Length == 10)
                  || (mobileNumber.StartsWith("99") && mobileNumber.Length == 9))
            {
                return "GTEL";
            }
            else
            {
                return "UNKNOWN";
            }
        }


    }
}